<?php
/**
 * @version $Id: install.extensionicons2.php 294 2007-12-07 23:42:27Z nik.elkuku $
 * repo $URL: http://joomla-codebase.googlecode.com/svn/trunk/extensionicons2/administrator/components/com_extensionicons2/install.extensionicons2.php $
 * Created on 14.04.2007
 * @package ExtensionIcons2
 * @author Nikolai Plath (elkuku)
 */

defined( '_JEXEC' ) or die( 'Restricted access' );

function com_install()
{

$etb_DEBUG = TRUE;

$C['APP_Name']			= 'EasyToolbar2';
$C['APP_Version']		= '0.0 SVN';
$C['APP_com_name']	= 'com_extensionicons2';
$C['APP_mod_name']	= 'mod_extensionicons2';

$configfile = JPATH_ADMINISTRATOR.DS.'components'.DS.$C['APP_com_name'].DS.$C['APP_com_name'].'.config.php';
if( file_exists( $configfile ))
{
	require( $configfile );
} else
{
	echo '<h2 style="color: red">CONFIG NOT FOUND !</h2>';
	if( $etb_DEBUG ) { echo $configfile.'<hr />'; }
	return FALSE;
}
$etb_CONFIG['APP_Name']			= $C['APP_Name'];
$etb_CONFIG['APP_Version']		= $C['APP_Version'];
$etb_CONFIG['APP_com_name']	= $C['APP_com_name'];
$etb_CONFIG['APP_mod_name']	= $C['APP_mod_name'];

	echo '<h2>Extension Icons</h2>';//no translation required ;)

$img_OK = '<img src="images/publish_g.png" /><br />';
$img_WARN = '<img src="images/publish_y.png" /><br />';
$img_ERROR = '<img src="images/publish_r.png" /><br />';
$BR = '<br />';

	/*
	 * Add new admin menu image
	 */
	$db = & JFactory::getDBO();//1.5

	$db->setQuery( "UPDATE #__components SET admin_menu_img = 'js/ThemeOffice/joomla_16x16.png' WHERE name= 'Extension Icons'");
	$OK = $db->query();

	  echo ( $OK ) ? JText::_('Icon created').$img_OK.$BR : JText::_('Icon NOT created').$img_WARN.$BR;
if( ! $OK && $etb_DEBUG ) echo $database->getErrorMsg();
	/*
	 * Add the Module
	 */
/*TODO writeable check !	
if ( !is_writable ( 'administrator/modules/' ) )
	{
    	echo'
		<h2 style="color:red">There was a problem with your installation</h2>
      	<p>The directory "' . $mosConfig_absolute_path . '/administrator/modules/" is not writeable</p>
        <p>Please:</p>
        <ul>
        <li>Uninstall Extension Icons</li>
        <li>Modify the file permissions</li>
        <li>Reinstall</li>
        </ul>
        <br/>Thanks.</p>';
	   return false;
	}
*/
/*

	$database->setQuery( "INSERT INTO `#__modules` (`title`, `content`, `ordering`, `position`, `checked_out`, `checked_out_time`, `published`, `module`, `numnews`, `access`, `showtitle`, `params`, `iscore`, `client_id`)"
				." VALUES ('Extension Icons', '', 0, 'header', 0, '0000-00-00 00:00:00', 1, 'mod_extensionicons', 0, 99, 0, '', 0, 1);");
	$database->query();
	$moduleID = $database->insertid();
	$database->setQuery( "INSERT INTO `#__modules_menu` (`moduleid`, `menuid`) VALUES ($moduleID, 0);");
	$database->query();

	$adminDir = dirname(__FILE__);

	/*
	$LangFile = $adminDir .'/language/'.$mosConfig_lang.'_mod_extensionicons.xml';
	if (file_exists($LangFile))

    {
        @rename( $LangFile, $mosConfig_absolute_path . '/administrator/modules/mod_extensionicons.xml');
    	echo 'Languagefile <strong>' . $mosConfig_lang . '</strong> found <img src="images/tick.png" /><br />';
		$insLang = $mosConfig_lang;


    } else
    {
        @rename( $adminDir . '/modules/mod_extensionicons.xml', $mosConfig_absolute_path . '/administrator/modules/mod_extensionicons.xml');
    	echo '<span style="color:red">'
    		. _EXICONS_INSTALL_NO_LANGUAGEFILE
    		. ' <strong>'
    		. $mosConfig_lang
    		. '</strong></span> <img src="images/publish_x.png" /><br />'
			. $LangFile . '<br />'
			. '... installing english <img src="images/tick.png" /><br />';
    	$insLang = 'English';
    }
    @rename( $adminDir . '/modules/mod_extensionicons.php', $mosConfig_absolute_path . '/administrator/modules/mod_extensionicons.php');

	echo _EXICONS_INSTALL_MODULE_INSTALLED . ': ' . $insLang . ' <img src="images/tick.png" /><br />';
*/

	$db = & JFactory :: getDBO();
	$TableName = $db->replacePrefix('#__extensionicons2');
	$query = "
CREATE TABLE IF NOT EXISTS `".$TableName."` (
  `id` int(11) NOT NULL auto_increment,
  `name` varchar(50) NOT NULL default '',
  `parent` int(11) unsigned NOT NULL default '0',
  `parent_name` varchar(255) NOT NULL default '',
  `admin_menu_link` varchar(150) NOT NULL default '',
  `admin_menu_alt` varchar(150) NOT NULL default '',
  `linkoption` varchar(50) NOT NULL default '',
  `ordering` int(11) NOT NULL default '0',
  `admin_menu_img` varchar(255) NOT NULL default '',
  `access_key` varchar(1) default NULL,
  `published` tinyint(1) NOT NULL default '0',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM;";

		$db->setQuery($query);
		$OK = $db->query();
	  if (!$OK) {
		  $mainframe->enqueueMessage(printDbErrors($db), 'error');

	
		//JError :: raiseError(500, $db->stderr());
		return FALSE;
	} else
	{
		echo JText::_('table created').$img_OK;
	}

//$query = "INSERT INTO `".$TableName."` (`id`, `name`, `parent`, `parent_name`, `admin_menu_link`, `admin_menu_alt`, `linkoption`, `ordering`, `admin_menu_img`, `access_key`, `published`)" .
//		$db->setQuery($query);
//		$OK = $db->query();
//	  echo ( $OK ) ? JText::_('Icon created').$img_OK : JText::_('Icon NOT created').$img_WARN;


$query = "INSERT INTO `".$TableName."`" .
		"\n (`id`, `name`, `parent`, `parent_name`, `admin_menu_link`, `admin_menu_alt`, `linkoption`, `ordering`, `admin_menu_img`, `access_key`, `published`)" .
		"\n VALUES" .
		"\n (1, 'Preview', 0, '', 'option=com_admin&amp;task=preview', 'Internal Preview', 'com_admin', 1, 'js/ThemeOffice/preview.png', NULL, 0),";
		"\n (2, 'Config', 0, '', 'option=com_config&amp;hidemainmenu=1', 'Global Config', 'com_config', 2, 'js/ThemeOffice/config.png', NULL, 1),";
		"\n (3, 'Extension Icons', 0, '', 'option=".$etb_CONFIG['APP_com_name']."', '".$etb_CONFIG['APP_Name']." Config', '".$etb_CONFIG['APP_com_name']."', 3, 'js/ThemeOffice/credits.png', 'X', 1),";
		"\n (4, 'Media Manager', 0, '', 'option=com_media', 'Media Manager', 'com_media', 0, 'js/ThemeOffice/mainmenu.png', NULL, 1),";
		"\n (5, 'Neuer Artikel', 0, '', 'option=com_content&task=add', 'Artikel einreichen', 'com_content', 0, 'js/ThemeOffice/categories.png', 'N', 1);";
		$db->setQuery($query);
		$OK = $db->query();
	  echo ( $OK ) ? JText::_('Icon created').$img_OK : JText::_('Icon NOT created').$img_WARN;
//$query = "INSERT INTO `".$TableName."` (`id`, `name`, `parent`, `parent_name`, `admin_menu_link`, `admin_menu_alt`, `linkoption`, `ordering`, `admin_menu_img`, `access_key`, `published`)" .
//		$db->setQuery($query);
//		$OK = $db->query();
//	  echo ( $OK ) ? JText::_('Icon created').$img_OK : JText::_('Icon NOT created').$img_WARN;
//$query = "INSERT INTO `".$TableName."` (`id`, `name`, `parent`, `parent_name`, `admin_menu_link`, `admin_menu_alt`, `linkoption`, `ordering`, `admin_menu_img`, `access_key`, `published`)" .
//		$db->setQuery($query);
//		$OK = $db->query();
//	  echo ( $OK ) ? JText::_('Icon created').$img_OK : JText::_('Icon NOT created').$img_WARN;
//$query = "INSERT INTO `".$TableName."` (`id`, `name`, `parent`, `parent_name`, `admin_menu_link`, `admin_menu_alt`, `linkoption`, `ordering`, `admin_menu_img`, `access_key`, `published`)" .
//		$db->setQuery($query);
//		$OK = $db->query();
//	  echo ( $OK ) ? JText::_('Icon created').$img_OK : JText::_('Icon NOT created').$img_WARN;


	/*
	 * Create directory for custom images
	 */
	$custom_dir = JPATH_SITE.DS.'images'.DS.'ExtensionIcons_Custom';
	@mkdir( $custom_dir );

	echo ( is_dir( $custom_dir )) ? JText::_('Custom directory created in').$img_OK.$custom_dir : JText::_('Unabled to create Custom directory in').$img_WARN.$custom_dir;

	/*
	 * Insert some Icons ;)
	 */
/*
	$database->setQuery( "INSERT INTO `#__extension_icons`" .
	"\n (`id`, `name`, `parent`, `parent_name`, `admin_menu_link`, `admin_menu_alt`, `linkoption`, `ordering`, `admin_menu_img`, `published`)" .
	"\n VALUES" .
	"\n (1, 'Preview', 0, '', 'option=com_admin&amp;task=preview', 'Preview', 'com_admin', 1, 'js/ThemeOffice/preview.png', 1)," .
	"\n (2, 'Config', 0, '', 'option=com_config&amp;hidemainmenu=1', 'Config', 'com_config', 2, 'js/ThemeOffice/config.png', 1)," .
	"\n (3, 'Extension Icons', 0, '', 'option=com_extensionicons', 'Extension Icons', 'com_extensionicons', 3, 'js/ThemeOffice/joomla_16x16.png', 1);");
	$database->query();
*/

	/*
	 * Thanx
	 */
	echo JText::_('_EXICONS_INSTALL_THANK_YOU') . '<img src="images/credits.png" /><br />';

	echo 'Made 2007 by <a href="http://www.nik-it.de">NiK-IT.de</a>';
}
?>
